import 'package:flutter/material.dart';
import 'tabIcon_data.dart';
import 'tab_icons.dart';

/// 底部导航参数
/// 指示器 还有凸出高度
// ignore: camel_case_types
class Bottom_Bar extends StatefulWidget {
  const Bottom_Bar({
    Key key,
    this.tabIconsList,
    this.changeIndex,
  }) : super(key: key);

  final Function(int index) changeIndex;
  final List<TabIconData> tabIconsList;

  @override
  _Bottom_BarState createState() => _Bottom_BarState();
}

// ignore: camel_case_types
class _Bottom_BarState extends State<Bottom_Bar> with TickerProviderStateMixin {
  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        boxShadow: const [
          BoxShadow(
              color: Colors.grey,
              offset: const Offset(0.0, 1.0),
              blurRadius: 4.0,
              spreadRadius: 0.0),
        ],
      ),
      child: Column(
        children: [
          /// 5个按钮
          SizedBox(
            height: 48,
            child: Padding(
              padding: const EdgeInsets.only(left: 15, right: 15),
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: TabIcons(
                      tabIconData: widget.tabIconsList[0],
                      removeAllSelect: () {},
                      onSelect: () {
                        widget.changeIndex(0);
                        setAnimation(0);
                      },
                    ),
                  ),
                  Expanded(
                    child: TabIcons(
                      tabIconData: widget.tabIconsList[1],
                      removeAllSelect: () {},
                      onSelect: () {
                        widget.changeIndex(1);
                        setAnimation(1);
                      },
                    ),
                  ),
                  Expanded(
                    child: TabIcons(
                      tabIconData: widget.tabIconsList[2],
                      removeAllSelect: () {},
                      onSelect: () {
                        widget.changeIndex(2);
                        setAnimation(2);
                      },
                    ),
                  ),
                  Expanded(
                    child: TabIcons(
                      tabIconData: widget.tabIconsList[3],
                      removeAllSelect: () {},
                      onSelect: () {
                        widget.changeIndex(3);
                        setAnimation(3);
                      },
                    ),
                  ),
                ],
              ),
            ),
          ),
          SizedBox(height: MediaQuery.of(context).padding.bottom / 1.6)
        ],
      ),
    );
  }

  void setAnimation(int index) {
    setState(() {
      widget.tabIconsList.forEach((TabIconData tab) {
        tab.isSelected = false;
        if (widget.tabIconsList[index].index == tab.index) {
          tab.isSelected = true;
        }
      });
    });
  }
}
